DT.DEFAULTS.postWithLoading = {
  errorFn: function (xhr, error, exception) {
    Utils.toastError(error);
  }
};
DT.DEFAULTS.toast = {
  closeButton: false,
  positionClass: "toast-top-center",
  showMethod: "show",
  showDuration: 200,
  hideDuration: 300,
  timeOut: 1000
};
DT.DEFAULTS.confirm = {
  title: "", // 标题
  type: "warning", // 类型
  customClass: "govSweetAlert",
  showCancelButton: true,
  closeOnConfirm: false,
  confirmButtonColor: "#DD6B55",
  confirmButtonText: "确定",
  cancelButtonText: "取消"
}

/**
 * 附件上传表单验证
 */
DT.Uploader = {
  validate: function (ctx) {
    var result = true;
    (ctx || $(document.body)).find("div.ditop-uploader").each(function () {
      var $ele = $(this), $uploader = $ele.data("uploader"),
        fileCount = $ele.data('fileCount') || 0, minFileNum = $ele.data("minFileNum"), stats = $uploader.getStats();
      if (stats.progressNum > 0) {
        result = false;
      }
    });
    if(!result){
      Utils.toastError("文件正在上传, 请等待上传完毕后提交。",{timeOut: 3000});
    }
    return result;
  }
};

$(document).on('click', '.navbar', function () {
  localStorage.removeItem('Ltop');
});

;(function () {

  /**
   * 验证码,支持手机号和邮件
   * 使用示例:  $("#gCode").veriCode({url: '/p/ryBaseInfo/sendMns',countDown:60, targetName: "mobile"});
   * @param ele
   * @param opt
   * countDown: 3,//倒计时总数
   * url: "",//后台发送验证码的url
   * targetName: "mobile"//邮箱地址或手机号的input的name
   */
  var veriCode = function (ele, opt) {
    var _this_ = this;
    this.DEFAULT = {
      countDown: 3,//倒计时总数
      url: "",//后台发送验证码的url
      targetName: "mobile"//邮箱地址或手机号的input的name
    };

    var i;
    veriCode.prototype.init = function () {
      ele.click(function () {
        _this_.chk();
      });
    };

    veriCode.prototype.chk = function () {
      _this_.setting = $.extend(true, {}, _this_.DEFAULT, opt);
      var isValid = $("input[name='" + _this_.setting.targetName + "']").valid();
      if (isValid) {
        ele.addClass("gCode_gray");
        _this_.render();
      }
    };

    veriCode.prototype.render = function () {
      ele.off('click');
      _this_.send();
      i = setInterval(function () {
        if (_this_.setting.countDown == 0) {
          ele.removeClass("gCode_gray");
          window.clearInterval(i);
          ele.text("重新获取").click(_this_.chk);
          return;
        }
        ele.text((_this_.setting.countDown) + "s");
        _this_.setting.countDown--;

      }, 1000);

    }
    veriCode.prototype.send = function () {
      if (_this_.setting.url) {
        Utils.post({
          url: _this_.setting.url,
          data: {"targatNo": $("input[name='" + _this_.setting.targetName + "']").val()},
        }, function (data) {
          console.debug(data)
        }, function (data) {
          console.debug(data)
        })
      } else {
        console.error("缺少url参数");
      }
    }
  }

  $.fn.extend({
    veriCode: function (opt) {
      new veriCode($(this), opt).init();
    }
  });

  /**
   * 人员选择插件
   * @param callback
   */
  var personSelect = function (callback) {
    Utils.openBox({
      title: '选择人员',
      area: ['700px', '600px'],
      ctx: parent,
      maxmin: true,
      url: '/p/common/personSelect',
      subWinCallback: function (data) {
        callback && callback(data)
      }
    })
  };

  $.fn.extend({
    personSelect: function (callback) {
      var $this = $(this);
      window.compId = $this.data("compid");//限制只能选某个企业下的人员
      window.multiple = $(this).data("multiple");//是否支持多选
      $this.click(function () {
        personSelect(callback)
      })
    }
  });

  var personAptSelect = function (callback) {
    Utils.openBox({
      title: '选择人员',
      area: ['700px', '600px'],
      ctx: parent,
      maxmin: true,
      url: '/p/common/personAptSelect',
      subWinCallback: function (data) {
        callback && callback(data)
      }
    })
  };

  $.fn.extend({
    personAptSelect: function (callback) {
      var $this = $(this);
      window.compId = $this.data("compid");//限制只能选某个企业下的人员
      window.type = $this.data("type");//大类别,例:注册人员,专业人员等
      window.profid = $this.data("profid");//专业id
      window.multiple = $(this).data("multiple");//是否支持多选
      $this.click(function () {
        personAptSelect(callback)
      })
    }
  });


  var leaderSelect = function (callback) {
    Utils.openBox({
      title: '选择技术负责人',
      area: ['700px', '600px'],
      ctx: parent,
      maxmin: true,
      url: '/p/common/leaderSelect',
      subWinCallback: function (data) {
        callback && callback(data)
      }
    })
  };

  $.fn.extend({
    leaderSelect: function (callback) {
      var $this = $(this);
      window.compId = $this.data("compid");//限制只能选某个企业下的人员
      window.multiple = $this.data("multiple");//是否支持多选
      window.selvals = $this.data("selvals");//默认选中项
      $this.click(function () {
        leaderSelect(callback)
      })
    }
  });


  //平台角色选择

  var roleSelect = function (callback) {
    Utils.openBox({
      title: '选择角色',
      area: ['360px', '500px'],
      ctx: parent,
      // maxmin: true,
      url: '/p/common/roleSelect',
      subWinCallback: function (data) {
        callback && callback(data)
      }
    })
  };

  $.fn.extend({
    roleSelect: function (callback) {
      var $this = $(this);
      window.role_multiple = $this.data("multiple");//是否支持多选
      window.role_plat = $this.data("plat");//展示哪些平台的角色
      $this.click(function () {
        if (!window.role_plat) {
          Utils.toastError("平台代码不能为空!");
          return;
        }
        roleSelect(callback)
      })
    }
  });

  setTimeout(function () {
    $(document).on('change', 'input, textarea', function () {
      var _thisVal = $(this).val();
      var type = $(this).attr("type");
      if (!type == "file") {
        $(this).val(filterXSS(_thisVal));
      }else{
        return false;
      }
    })
  });

})(jQuery);

template.defaults.imports.formatAptItemName = function (str) {
  return str != null ? str.replace(/,/g,"\n"):'-';
};

//art-template 添加自定义方法
//日期格式化
template.defaults.imports.formatDate = function (time, format) {
  if (time && typeof  time === 'number') {
    return new Date(time).format(format)
  }
  return time;
};

//2017-10-10 2017年10月10日
template.defaults.imports.formatStrDate = function (date, format) {

  date = new Date(date);
  var map = {
    "M": date.getMonth() + 1, //月份
    "d": date.getDate(), //日
    "h": date.getHours(), //小时
    "m": date.getMinutes(), //分
    "s": date.getSeconds(), //秒
    "q": Math.floor((date.getMonth() + 3) / 3), //季度
    "S": date.getMilliseconds() //毫秒
  };

  format = format.replace(/([yMdhmsqS])+/g, function (all, t) {
    var v = map[t];
    if (v !== undefined) {
      if (all.length > 1) {
        v = '0' + v;
        v = v.substr(v.length - 2);
      }
      return v;
    }
    else if (t === 'y') {
      return (date.getFullYear() + '').substr(4 - all.length);
    }
    return all;
  });
  return format;
}

//处罚类型展示
template.defaults.imports.publishType = function (str) {
  if (str.length > 0) {
    var arr = str.split(','),strHtml = "";
    arr.forEach(function (item) {
      strHtml += "<span>"+item+"</span>";
    });
    return strHtml
  }
  return "-";
}

template.defaults.imports.separate = function (str,type) {
  var arr = [];
  arr = str.split("-");
  if (type == "0") {
    return arr[0]
  } else if (type == "1") {
    return arr[1]
  }
  return "-";
}

/*var area = ['300px', '200px'];*/
var area = ['300px'];
var topTitle = "提示";
var skin = "dt-confirm";
//公共消息组件
var CompUtils = {
  success: function (title, countdown) {
    layer.open({
      title: topTitle,
      skin: "dt-success",
      icon: 1,
      type: 0,
      area: area,
      btn: ['确定'], //按钮,
      content: "<div class='dt_confirm'>" + title + "</div>",
    });
  },
  countdownSuccess: function (title, countdown) {
    layer.open({
      title: topTitle,
      closeBtn: 0,
      skin: "dt-success-countdown",
      icon: 1,
      type: 0,
      area: area,
      btn: ['<span class="countdown"><span class="second">' + countdown + '</span> s后自动关闭</span>'], //按钮,
      content: "<div class='dt_confirm'>" + title + "</div>",
      yes: function (index, layero) {
        window.clearInterval(i);
        layer.close(index); //如果设定了yes回调，需进行手工关闭
      },
      end: function (index) {
        window.clearInterval(i);
      }
    });

    i = setInterval(function () {
      countdown = --countdown;
      if (countdown === 0) {
        window.clearInterval(i);
        layer.closeAll()
      }
      $(".second").html(countdown);
    }, 1000);
  },
  confirm: function (optoin, btn1Callback, btn2Callback) {
    layer.open({
      title: topTitle,
      closeBtn: 0,
      skin: "dt-confirm",
      icon: 0,
      type: 0,
      area: optoin.area || area,
      btn: optoin.btn, //按钮
      content: "<div class='dt_confirm'>" + optoin.title + "</div>",
      yes: function (index, layero) {
        btn1Callback && btn1Callback();
        layer.close(index); //如果设定了yes回调，需进行手工关闭
      },
      btn2: function (index, layero) {
        btn2Callback && btn2Callback();
      }
    });
  },
  confirmPlus: function (optoin, btn1Callback, btn2Callback) {
    layer.open({
      title: topTitle,
      closeBtn: 0,
      skin: optoin.skin || skin,
      type: 0,
      area: optoin.area || area,
      btn: optoin.btn, //按钮
      content: "<div class='dt_confirm_plus_title'>" + optoin.title + "</div><div class='dt_confirm_plus_tip'>" + optoin.tip + "</div>",
      yes: function (index, layero) {
        btn1Callback && btn1Callback();
        layer.close(index); //如果设定了yes回调，需进行手工关闭
      },
      btn2: function (index, layero) {
        btn2Callback && btn2Callback();
      }
    });
  },
  error: function (title) {
    layer.open({
      title: topTitle,
      closeBtn: 0,
      skin: "dt-error",
      icon: 2,
      type: 0,
      area: area,
      btn: ['确定'], //按钮
      content: "<div class='dt_confirm'>" + title + "</div>",
      yes: function (index, layero) {
        layer.close(index); //如果设定了yes回调，需进行手工关闭
      }
    });

    /*layer.confirm("<div class='dt_confirm'>" + msg + "</div>", {
      title: "提示",
      area: ['300px', '210px'],
      icon: 2,
      area: area,
      btn: ['关闭'] //按钮
    });*/
  },


};

//表格合并
function mergeTable(tb, stacol, endcol, bool, num) {
  var end;
  var i = 0;
  var j = 0;
  var rowCount = tb.rows.length;
  var colCount = tb.rows[0].cells.length;
  var obj1 = null;
  var obj2 = null;
  var n = 5;
  var count = new Array();
  for (i = 0; i < rowCount; i++) {
    for (j = 0; j < colCount; j++) {
      if (typeof (tb.rows[i].cells[j]) != "undefined") {
        tb.rows[i].cells[j].id = "tb__" + i + "_" + j
      }
    }
  }
  if (typeof (num) != "undefined") {
    obj1 = document.getElementById("tb__0_" + (num - 1).toString());
    for (var t = 1; t < rowCount; t++) {
      obj2 = document.getElementById("tb__" + t.toString() + "_" + (num - 1).toString());
      if (obj1.innerHTML == obj2.innerHTML) {
        obj1.rowSpan++;
        obj2.parentNode.removeChild(obj2)
      } else {
        count[t] = n;
        obj1 = document.getElementById("tb__" + t.toString() + "_" + (num - 1).toString())
      }
    }
  }
  for (i = 0; i < colCount; i++) {
    if (bool) {
      if (i + 1 < stacol || i + 1 > endcol) {
        continue
      }
    } else {
      if (i + 1 > stacol && i + 1 < endcol) {
        continue
      }
    }
    obj1 = document.getElementById("tb__0_" + i.toString());
    for (j = 1; j < rowCount; j++) {
      obj2 = document.getElementById("tb__" + j.toString() + "_" + i.toString());
      if (typeof (count[j]) != "undefined") {
        if (count[j] != n) {
          if (obj1.innerHtml == obj2.innerHtml) {
            obj1.rowSpan++;
            obj2.parentNode.removeChild(obj2)
          } else {
            obj1 = document.getElementById("tb__" + j.toString() + "_" + i.toString())
          }
        } else {
          obj1 = document.getElementById("tb__" + j.toString() + "_" + i.toString())
        }
      } else {
        if (obj1 && obj2 && obj1.innerHTML == obj2.innerHTML) {
          obj1.rowSpan++;
          obj2.parentNode.removeChild(obj2)
        } else {
          obj1 = document.getElementById("tb__" + j.toString() + "_" + i.toString())
        }
      }
    }
  }
};

//批量组件
var batchUtils = {
  progress: function (option) {
    var progressContext = '<div class="progress-box">' +
      '<h3>loading...</h3>' +
      '<div class="progress">' +
      '<div class="progress-bar progress-bar-blue progress-bar-striped" role="progressbar" data-transitiongoal=""></div>' +
      '<div class="progress-bar-image progress-bar-striped active" style="width: 100%"></div>' +
      '</div>' +
      '<p class="progress-Text">本次共提交 <span class="submit-bar">' + option.totalCnt + '</span> 条，已完成 <span class="complete-bar">' + option.sucCnt + '</span> 条，失败 <span class="error-bar">' + option.failCnt + '</span> 条。</p>' +
      '</div>' +
      '<footer class="footer button-actions">' +
      '<button type="button" class="btn btn-primary closeBtn" disabled="disabled">确定</button>' +
      '</footer>';
    if (option.sucCnt == 0 && option.failCnt == 0) {
      $('body').html(progressContext);
    }
    layer.getOpenFromWindow().closeSwitch(1);
    progressMtion(option);

    $(".closeBtn").off("click").on("click", function () {
      closeCall();
    });

    function progressMtion(option) {
      if (option.speedCnt <= 10) {
        option.speedCnt = 10;
      }
      $('.progress .progress-bar').attr('data-transitiongoal', option.speedCnt).progressbar();
      setTimeout(function () {
        $('.complete-bar').html(option.sucCnt);
        $('.error-bar').html(option.failCnt);
      }, 600);
      var sum = option.sucCnt + option.failCnt;
      if (option.totalCnt == sum) {
        setTimeout(function () {
          layer.getOpenFromWindow().closeSwitch(0);
          $(".closeBtn").removeAttr("disabled");
        }, 600);
      }
    }

    function closeCall() {
      window.dtLayerCallback();
      layer.closeCurrent(window);
    }
  },
  progressActivate: function (option) {
    var progressContext = '<div class="progress-box">' +
      '<h3>loading...</h3>' +
      '<div class="progress">' +
      '<div class="progress-bar progress-bar-blue progress-bar-striped" role="progressbar" data-transitiongoal=""></div>' +
      '<div class="progress-bar-image progress-bar-striped active" style="width: 100%"></div>' +
      '</div>' +
      '<p class="progress-Text">本次共取消挂起 <span class="submit-bar">' + option.totalCnt + '</span> 条，已完成 <span class="complete-bar">' + option.sucCnt + '</span> 条，失败 <span class="error-bar">' + option.failCnt + '</span> 条。</p>' +
      '</div>' +
      '<footer class="footer button-actions">' +
      '<button type="button" class="btn btn-primary closeBtn" disabled="disabled">确定</button>' +
      '</footer>';
    if (option.sucCnt == 0 && option.failCnt == 0) {
      $('body').html(progressContext);
    }
    layer.getOpenFromWindow().closeSwitch(1);
    progressMtion(option);

    $(".closeBtn").off("click").on("click", function () {
      closeCall();
    });

    function progressMtion(option) {
      if (option.speedCnt <= 10) {
        option.speedCnt = 10;
      }
      $('.progress .progress-bar').attr('data-transitiongoal', option.speedCnt).progressbar();
      setTimeout(function () {
        $('.complete-bar').html(option.sucCnt);
        $('.error-bar').html(option.failCnt);
      }, 600);
      var sum = option.sucCnt + option.failCnt;
      if (option.totalCnt == sum) {
        setTimeout(function () {
          layer.getOpenFromWindow().closeSwitch(0);
          $(".closeBtn").removeAttr("disabled");
        }, 600);
      }
    }

    function closeCall() {
      window.dtLayerCallback();
      layer.closeCurrent(window);
    }
  },
  unique: function (arr) {
    var result = [], isRepeated;
    for (var i = 0; i < arr.length; i++) {
      var flowOrderIdArr = [], taskNodeIdArr = [], resultArr = [], commentArr = [];
      isRepeated = false;
      flowOrderIdArr.push(arr[i].flowOrderId);
      taskNodeIdArr.push(arr[i].taskNodeId);
      if (arr[i].result != undefined || arr[i].result != null) {
        resultArr.push(arr[i].result);
      } else {
        resultArr.push('');
      }
      if (arr[i].comment != undefined || arr[i].comment != null) {
        commentArr.push(arr[i].comment);
      } else {
        commentArr.push('-');
      }
      for (var j = 0; j < result.length; j++) {
        if (arr[i].bindex == result[j].bindex) {
          flowOrderIdArr.push(result[j].flowOrderId);
          taskNodeIdArr.push(result[j].taskNodeId);
          if (result[j].result != undefined || result[j].result != null) {
            resultArr.push(result[j].result);
          } else {
            resultArr.push('');
          }
          if (result[j].comment != undefined || result[j].comment != null) {
            commentArr.push(result[j].comment);
          } else {
            commentArr.push('-');
          }
          result[j].flowOrderId = flowOrderIdArr.join(',');
          result[j].taskNodeId = taskNodeIdArr.join(',');
          result[j].result = resultArr.join(',');
          result[j].comment = commentArr.join('@');
          isRepeated = true;
          break;
        }
      }
      if (!isRepeated) {
        result.push(arr[i]);
      }
    }
    return result;
  },
  reSort: function (tasks) {
    var arr = new Array();
    if (tasks && tasks.length > 0) {
      var groups = {};
      tasks.forEach(function (t) {
        groups[t.bindex] = groups[t.bindex] || new Array();
        groups[t.bindex].push(t);
      });
      var index = 1;
      for (var key in groups) {
        groups[key].forEach(function (item) {
          item.bindex = index;
        })
        index++;
        arr = arr.concat(groups[key]);
      }
    }
    return arr;
  },
  uniqueArr: function (arr) {
    var result = [], isRepeated;
    for (var i = 0; i < arr.length; i++) {
      var flowOrderIdArr = [], taskNodeIdArr = [], resultArr = [], commentArr = [];
      isRepeated = false;
      flowOrderIdArr.push(arr[i].flowOrderId);
      taskNodeIdArr.push(arr[i].taskNodeId);
      if (arr[i].result != undefined || arr[i].result != null) {
        resultArr.push(arr[i].result);
      } else {
        resultArr.push('');
      }
      if (arr[i].comment != undefined || arr[i].comment != null) {
        commentArr.push(arr[i].comment);
      } else {
        commentArr.push('-');
      }
      for (var j = 0; j < result.length; j++) {
        if (arr[i].bindex == result[j].bindex) {
          flowOrderIdArr.push(result[j].flowOrderId);
          taskNodeIdArr.push(result[j].taskNodeId);
          if (result[j].result != undefined || result[j].result != null) {
            resultArr.push(result[j].result);
          } else {
            resultArr.push('');
          }
          if (result[j].comment != undefined || result[j].comment != null) {
            commentArr.push(result[j].comment);
          } else {
            commentArr.push('-');
          }
          result[j].flowOrderId = flowOrderIdArr.join(',');
          result[j].taskNodeId = taskNodeIdArr.join(',');
          result[j].result = resultArr.join(',');
          result[j].comment = commentArr.join('@');
          isRepeated = true;
          break;
        }
      }
      if (!isRepeated) {
        result.push(arr[i]);
      }
    }
    return result;
  },
  uniqueSelect: function (arr) {
    var result = [], isRepeated;
    for (var i = 0; i < arr.length; i++) {
      isRepeated = false;
      for (var j = 0; j < result.length; j++) {
        if (arr[i].bindex&&arr[i].bindex == result[j].bindex) {
          isRepeated = true;
          break;
        }
      }
      if (!isRepeated) {
        result.push(arr[i]);
      }
    }
    return result;
  },
  mergeTable: function (tb) {
    var rowCount = tb.rows.length;
    var colCount = tb.rows[0].cells.length;
    for (var r = 1; r < rowCount; r++) {
      for (var c = 0; c < colCount; c++) {
        var cell = tb.rows[r].cells[c];
        cell && (cell.id = "tb__" + r + "_" + c);
      }
    }
    merge_0(0, 1, rowCount - 1, function (sRow, eRow) {
      merge_0(1, sRow, eRow);
      merge_0(2, sRow, eRow)
    });

    function merge_0(col, sRow, eRow, fn) {
      var startRow = sRow, mcount = 0;
      var obj1 = document.getElementById("tb__" + startRow + "_" + col);
      for (var r = startRow + 1; r <= eRow; r++) {
        var obj2 = document.getElementById("tb__" + r + "_" + col);
        if (obj1.innerHTML === obj2.innerHTML) {
          obj1.rowSpan++;
          mcount++;
          obj2.parentNode.removeChild(obj2)
        } else {
          mcount !== 0 && fn && fn(startRow, startRow + mcount);
          startRow = r;
          mcount = 0;
          obj1 = document.getElementById("tb__" + r + "_" + col)
        }
      }
      mcount !== 0 && fn && fn(startRow, startRow + mcount);
    }
  },
  drag: function (option) {
    var eleLeft = option.leftBox.offset().left,
      isMouseDown = false,
      borderLen = 2,
      conWidth = option.conBox.width(),
      eleRightBox = option.rightBox;

    option.leftBox.bind({
      mousedown: function (e) {
        var ele = $(this);
        var rightPos = eleLeft + ele.width() + borderLen;
        if (rightPos - 10 <= e.pageX && e.pageX <= rightPos) {
          isMouseDown = true;
        }
      }
    });

    $('body').bind({
      mousemove: function (e) {
        var ele = option.leftBox;
        var rightPos = eleLeft + ele.width() + borderLen;

        if (rightPos - 10 <= e.pageX && e.pageX <= rightPos) {
          ele.css('cursor', 'e-resize');
        } else {
          if (!isMouseDown) {
            ele.css('cursor', 'auto');
          }
        }
        if (isMouseDown) {
          if ((e.pageX - eleLeft - borderLen - 35) < 200) {
            ele.width('200px');
            eleRightBox.width((conWidth - 235) + 'px');
          } else if ((e.pageX - eleLeft - borderLen - 35) > 800) {
            ele.width('800px');
            eleRightBox.width((conWidth - 835) + 'px');
          } else {
            ele.width((e.pageX - eleLeft - borderLen) + 'px');
            eleRightBox.width((conWidth - (e.pageX - eleLeft - borderLen) - 2) + 'px');
          }
        }
      },
      mouseup: function (e) {
        isMouseDown = false;
      }
    });
  }
}

snippets.bootstrapTable.auditTimeoutFormatter = function (value, row, index) {
  if (value) {
    value = parseInt(value);
    if (value < 24) {
      return value + "小时";
    }
    return Math.floor(value / 24) + "天";
  }
};

function getCounty() {
  var city = $("#city").val();
  if(city == ''){
    $("#county").html("<option value=''>全部</option>");
  }else{
    $.ajax({
      method: "POST",
      url: "/g/common/getCounty",
      data: {
        city: city
      },
      success: function (data) {
        var html = "<option value=''>全部</option>";
        if (data) {
          data.forEach(function (val) {
            html += "<option value='" + val.regionCode + "'>" + val.regionName + "</option>";
          });
          $("#county").html(html);
          $("#filterBar").dtFilter("resetFieldConfig", $("#county"));
        }
      }
    });
  }
}

//表格筛选展开收起
function expand(){
  var node=$(".searchHead");
  var el=$(".searchText span");
  if(!node.hasClass('expand')){
    node.addClass('expand');
    el.html("收起全部搜索项<strong></strong>");
  }else{
    node.removeClass('expand');
    el.html("展开全部搜索项<strong></strong>");
  }
}
function expandLoad() {
  var flag=$('.page-content .heading').hasClass('head_search');
  var $el=$('.searchHead');
  $el.next('.searchText').remove()
  if(flag&&$el.find('.searchLeft').outerHeight()>68){
    $el.after('<p class="searchText"><span onclick="expand()">展开全部搜索项<strong></strong></span></p>')
  }
}
function expandRefresh(){
  if($(".heading").hasClass('heading')){
    expandLoad();
    window.onresize=function () {
      expandLoad()
    };
  }
}
window.onload=function () {
  expandRefresh()
};

// 刷新页面
function refresh_gov() {
  $("#filterBar").dtFilter("render2");
  $('.choice_data_txt').hide();
}

var listCompStatus = {
  bootstrapTable: {
    compNameClass: function (value, row, index) {
      if (row.provincial == '1') {
        return "provClass";
      }else{
        return row.provincial;
      }
    }
  }
}

// 时间加减
function DateAdd(interval, number, date) {
  switch (interval) {
    case "y": {
      date.setFullYear(date.getFullYear() + number);
      return date;
      break;
    }
    case "q": {
      date.setMonth(date.getMonth() + number * 3);
      return date;
      break;
    }
    case "m": {
      date.setMonth(date.getMonth() + number);
      date.setDate(date.getDate() - 1);
      return date;
      break;
    }
    case "w": {
      date.setDate(date.getDate() + number * 7);
      return date;
      break;
    }
    case "d": {
      date.setDate(date.getDate() + number);
      return date;
      break;
    }
    case "h": {
      date.setHours(date.getHours() + number);
      return date;
      break;
    }
    case "m": {
      date.setMinutes(date.getMinutes() + number);
      return date;
      break;
    }
    case "s": {
      date.setSeconds(date.getSeconds() + number);
      return date;
      break;
    }
    default: {
      date.setDate(d.getDate() + number);
      return date;
      break;
    }
  }
}

/*时间算法--只月份相加并日期默认少一天*/
var getDate = {
  getDateRange: function (startDate,number) {
    var date = new Date(startDate);
    date.setMonth(date.getMonth() + parseInt(number));
    date.setDate(date.getDate() - 1);
    return date.format("yyyy-MM-dd");
  }
}

/**
 * 资质附件展示
 */

var fileShow = {
  reviewPage : function (data) {
    var fileHtml = "";
    if (data && data.length != 0) {
      for (var i = 0; i < data.length; i++) {
        try {
          fileHtml += "<p id='" + data[i].directoryCode + "'> " + data[i].directoryName + "</p>";
          if (data[i].fileList && data[i].fileList.length != 0) {
            for (var j = 0; j < data[i].fileList.length; j++) {
              try {
                var typeStr = data[i].fileList[j].mimeType.split("/")[1].toLowerCase();
                if (typeStr == "pdf") {
                  fileHtml += "<iframe id='" + data[i].fileList[j].fileId + "' scrolling='no' src='/a/file/view?fileId=" + data[i].fileList[j].fileId + "'></iframe>";
                } else {
                  fileHtml += "<img class='viewerImg' id='" + data[i].fileList[j].fileId + "' src='/a/file/thumb/" + data[i].fileList[j].fileId + "'/>";
                }
              } catch (e) {
                fileHtml += "<div class='no-data'></div>";
              }
            }
          } else {
            fileHtml += "<div class='no-data'></div>";
          }
        } catch (e) {
          fileHtml += "<div class='no-data'></div>";
        }
      }
    } else {
      fileHtml = "<div class='no-data'></div>";
    }
    this.telLoad(fileHtml);
  },
  reviewPeoplePage : function (staffId, data) {
    var fileHtml = "<p id='" + staffId + "'>身份证</p><iframe style='height:630px' scrolling='no' src='/g/audit/buildingQual/staffCard/" + staffId + "'></iframe>";
    if(data && data.length != 0) {
      for (var i = 0; i < data.length; i++) {
        try {
          fileHtml += "<p id='" + data[i].fileList[0].fileId + "'>" + data[i].directoryName + "</p>";
          if (data[i].fileList && data[i].fileList.length != 0) {
            for (var j = 0; j < data[i].fileList.length; j++) {
              var typeStr = data[i].fileList[j].mimeType.split("/")[1].toLowerCase();
              if (typeStr == "pdf") {
                fileHtml += "<iframe scrolling='no' src='/a/file/view?fileId=" + data[i].fileList[j].fileId + "'></iframe>";
              } else {
                fileHtml += "<img class='viewerImg' src='/a/file/thumb/" + data[i].fileList[j].fileId + "'/>";
              }
            }
          } else {
            fileHtml += "<div class='no-data'></div>";
          }
        } catch (e) {
          fileHtml += "<div class='no-data'></div>";
        }
      }
    }
    $(".pdfCont .pdfContCon").html(fileHtml);
    $('.viewerImg').viewerImg();
  },
  reviewperforPage : function (fileList) {
    var fileHtml = "";
    if (fileList && fileList.length != 0) {
      for (var k = 0; k < fileList.length; k++) {
        var data = fileList[k].data;
        for (var i = 0; i < data.length; i++) {
          if (data[i].fileList && data[i].fileList.length != 0) {
            for (var j = 0; j < data[i].fileList.length; j++) {
              fileHtml += data.length > 1?"<p id='" + data[i].fileList[j].fileId +"'> " + data[i].directoryName + "_" + (i+1) + "</p>": "<p id='" + data[i].fileList[j].fileId +"'> " + data[i].directoryName + "</p>";
              var typeStr = data[i].fileList[j].mimeType.split("/")[1].toLowerCase();
              if (typeStr == "pdf") {
                fileHtml += "<iframe  scrolling='no' src='/a/file/view?fileId=" + data[i].fileList[j].fileId + "'></iframe>";
              } else {
                fileHtml += "<img class='viewerImg' src='/a/file/thumb/" + data[i].fileList[j].fileId + "'/>";
              }
            }
          } else {
            fileHtml += data.length > 1?"<p id='"+data[i].directoryCode+"'> " + data[i].directoryName + "_" + (i+1) + "</p>": "<p id='"+data[i].directoryCode+"'> " + data[i].directoryName + "</p>";
            fileHtml += "<div class='no-data'></div>";
          }
        }
      }
    } else {
      fileHtml = "<div class='no-data'></div>";
    }
    this.telLoad(fileHtml);

  },
  telLoad : function(fileHtml){
    var _this = this;
    var arr = [];
    arr = fileHtml.split("</iframe>");
    arr = $.grep(arr, function (item) {
      return item != "";
    });
    for (var i = 0; i < arr.length; i++) {
      arr[i] += "</iframe>";
    }

    var index = 0;
    setTimeFn();
    function setTimeFn() {
      if(arr.length >= (index+1)){
        $(".pdfCont .pdfContCon").append(arr[index])
        if($(".pdfContCon iframe").length > 1){
          $(".pdfContCon iframe").eq(index-1).on('load',function(){
            index++;
            setTimeout(setTimeFn(arr),0)
          })
        }else{
          index++;
          setTimeout(setTimeFn(arr),0)
        }
        $('.viewerImg').viewerImg();
        _this.onePdf();
        /*debugger
				if(arr.length == (index+1)){
          $('.viewerImg').viewerImg();
          _this.onePdf();
				}*/
      }else{
        return
      }
    }
  },
  onePdf : function(){
    $pdfHtml = $(".pdfCont .pdfContCon");
    if($pdfHtml.children("iframe").length == 1){
      if($pdfHtml.children('p').length >= 1){
        var Height = $pdfHtml.children('p').innerHeight();
      }else{
        var Height = $pdfHtml.children('h3').innerHeight();
      }
      $pdfHtml.children("iframe").css({
        height:'calc(100% - '+Height+'px)',
        marginBottom: 0
      });
    }
  },
  baPostFlie : function (bitemId,fileRelIds) {
    Utils.postWithLoading({
      url: "/g/file/getFileList",
      data: {"bitemId": bitemId, "fileRelIds": fileRelIds},
      success: function (data) {
        fileShow.reviewBaTelPage(data);
      },
      error: function () {
        Utils.toastError("操作失败！");
      }
    });
  },
  baPostFlieNoHead : function (bitemId,fileRelIds) {
    Utils.postWithLoading({
      url: "/g/file/getBaFileList",
      data: {"bitemId": bitemId, "fileRelIds": fileRelIds},
      success: function (data) {
        fileShow.reviewBaTelPage(data);
      },
      error: function () {
        Utils.toastError("操作失败！");
      }
    });
  },
  reviewBaTelPage : function (dataJson) {
    var data = [];
    for (var key in dataJson.obj) {
      for (var attr in dataJson.obj[key]) {
        dataJson.obj[key][attr].directionCode = attr;
        data.push($.extend({}, dataJson.obj[key][attr]))
      }
    }
    // $(".pdfCont .pdfContCon").html(template("viewFile", {"obj": fileData}));
    var fileHtml = "";
    if (data && data.length != 0) {
      for (var i = 0; i < data.length; i++) {
        fileHtml += "<p id='"+data[i].directoryCode+"'> " + data[i].directoryName + "</p>";
        if (data[i].itemList && data[i].itemList.length != 0) {
          for (var j = 0; j < data[i].itemList.length; j++) {
            try {
              var typeStr = data[i].itemList[j].mimeType.split("/")[1].toLowerCase();
              if (typeStr == "pdf") {
                fileHtml += "<iframe id='" + data[i].itemList[j].fileId + "' scrolling='no' src='/a/file/view?fileId=" + data[i].itemList[j].fileId + "'></iframe>";
              } else {
                fileHtml += "<img class='viewerImg' id='" + data[i].itemList[j].fileId + "' src='/a/file/thumb/" + data[i].itemList[j].fileId + "'/>";
              }
            } catch (e) {
              fileHtml += "<div class='no-data'></div>";
            }
          }
        } else {
          fileHtml += "<div class='no-data'></div>";
        }
      }
    } else {
      fileHtml = "<div class='no-data'></div>";
    }
    this.telLoad(fileHtml);
  },
  reviewBaPage : function (data) {
    var fileHtml = "";
    if (data && data.length > 0) {
      for (var i = 0; i < data.length; i++) {
        fileHtml += ' <h3 class="titleBan margin-bottom-20" style="text-align: left;"> ' + data[i].directoryName + '</h3>';
        if (data[i].itemList && data[i].itemList.length > 0) {
          for (var j = 0; j < data[i].itemList.length; j++) {
            var typeStr = data[i].itemList[j].mimeType.split("/")[1].toLowerCase();
            if (typeStr == "pdf") {
              fileHtml += "<iframe scrolling='no' src='/a/file/view?fileId=" + data[i].itemList[j].fileId + "'></iframe>";
            } else {
              fileHtml += "<img class='viewerImg' src='/a/file/raw/" + data[i].itemList[j].fileId + "'/>";
            }
          }
        } else {
          fileHtml += "<div class='no-data'></div>";
        }
      }
    } else {
      fileHtml = "<div class='no-data'></div>";
    }

    $(".pdfCont .pdfContCon").html(fileHtml);
    $('.viewerImg').viewerImg();
    this.onePdf();
  },
  reviewBaEquipPage : function (data) {
    var fileHtml = "";
    if (data && data.length > 0) {
      for (var i = 0; i < data.length; i++) {
        fileHtml += ' <h3 class="titleBan margin-bottom-20" style="text-align: left;"> ' + data[i].directoryName + '</h3>';
        if (data[i].fileList && data[i].fileList.length > 0) {
          for (var j = 0; j < data[i].fileList.length; j++) {
            var typeStr = data[i].fileList[j].mimeType.split("/")[1].toLowerCase();
            if (typeStr == "pdf") {
              fileHtml += "<iframe scrolling='no' src='/a/file/view?fileId=" + data[i].fileList[j].fileId + "'></iframe>";
            } else {
              fileHtml += "<img class='viewerImg' src='/a/file/thumb/" + data[i].fileList[j].fileId + "'/>";
            }
          }
        } else {
          fileHtml += "<div class='no-data'></div>";
        }
      }
    } else {
      fileHtml = "<div class='no-data'></div>";
    }

    $(".pdfCont .pdfContCon").html(fileHtml);
    $('.viewerImg').viewerImg();
    this.onePdf();
  }
}

/*企业证书检验*/
var check = {
  cert: function (applyIds,nodeName,result,callBack) {
    var _this = this;
    Utils.postWithLoading({
      url: "/g/audit/buildingQual/checkCertificate",
      data:{
        applyIds : applyIds || ""
      },
      success: function (data) {
        if(data.success){
          if(data.obj.length > 0 && result == "1"){
            _this.certAlert(data.obj,nodeName,callBack)
          }else{
            callBack()
          }
        }
      },
      error: function (xhr, error, exception) {
        Utils.toastError(error);
      }
    });
  },
  certSafety: function (applyIds,nodeName,result,callBack) {
    var _this = this;
    Utils.postWithLoading({
      url: "/g/qyCertSafetyApply/checkCertificate",
      data:{
        applyIds : applyIds || ""
      },
      success: function (data) {
        if(data.success){
          if(data.obj.length > 0 && result == "1"){
            _this.certAlert(data.obj,nodeName,callBack)
          }else{
            callBack()
          }
        }
      },
      error: function (xhr, error, exception) {
        Utils.toastError(error);
      }
    });
  },
  certAlert: function(certData,nodeName,callBack){
    if(nodeName == "审核"){
      layer.open({
        type: 1,
        skin: "checkCertAlert",
        title: "资质证书信息",
        closeBtn: 1,
        area: ['440px'],
        content: '<div class="certCon">\n'
          + '        <div class="certText">\n'
          + '          <p><span class="compNameTxt"><b style="color:#830000">'+certData[0].compName+'</b></span>当前资质证书已失效，是否修改<span class="nodeName">'+nodeName+'</span>意见再进行提交。</p>\n'
          + '        </div>\n'
          + '    </div>',
        btn: ['无需修改','修改意见'],
        yes: function (index) {
          callBack();
          layer.close(index);
        }
      });
    }else if(nodeName == "审批"){
      layer.open({
        type: 1,
        skin: "checkCertAlert",
        title: "资质证书信息",
        closeBtn: 1,
        area: ['440px'],
        content: '<div class="certCon">\n'
          + '        <div class="certText">\n'
          + '          <p><span class="compNameTxt"><b style="color:#830000">'+certData[0].compName+'</b></span>当前资质证书已失效，办件不能进行<span class="nodeName">'+nodeName+'</span>同意，请修改意见后再次进行提交。</p>\n'
          + '        </div>\n'
          + '    </div>',
        btn: ['我知道了'],
        yes: function (index) {
          layer.close(index);
        }
      });
    }

  }
}

/**
 * 图片查看插件
 */

$.fn.extend({
  viewerImg: function (param) {
    var params = '';
    if(!param){
      params = {
        navbar: false
      }
    }else{
      params = param
    }
    this.viewer(params);
  }
});





